#include "DBCommon.h"

using namespace databaselib::io;

AgentDB::AgentDB()
{
	AgentDBManager::getInstance()->insert( this );
}

AgentDB::~AgentDB()
{
	releaseDataBaseEnv();
}

Database *AgentDB::getDataBase()
{
	databaselib::io::Database *database = m_databaseList.pop();
	if ( database ) return ( database );
	database = getNewDBInstance();
	return ( database );
}

void AgentDB::release()
{
	m_databaseList.removeAllMemory();
}

bool AgentDB::checkDBConnect( Database *database )
{
	databaselib::io::Database *newInstance = database;
	if ( !database->isConnect() )
	{
		newInstance = getNewDBInstance();

		delete database;
	}
	m_databaseList.push( newInstance );

	return ( false );
}



void AgentDB::releaseDB()
{
	AgentDBManager::getInstance()->release();
}
